/** *******************************************************************
 * Amfphp Redux
 * @author  Jonnie Spratley
 * @see jonniespratley@gmail.com
 * @internal
 ******************************************************************* */
package com.jonniespratley.amfphpredux.business
{
	import com.adobe.cairngorm.business.ServiceLocator;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;

	/**
	 * The Business Delegate delegates all the responsibility for the
	 * business logic that must locate a service, and then invokes
	 * a method on the service.
	 *
	 */
	public class AmfphpReduxServiceDelegate
	{
		private var responder:IResponder;
		private var service:Object;

		public function AmfphpReduxServiceDelegate( responder:IResponder )
		{
			this.service = ServiceLocator.getInstance().getRemoteObject( "AmfphpReduxService" );
			this.responder = responder;
		}

		/************** ServiceCalls ********************/
		
		
		public function getDatabases( aHost:String, aPort:String, aUsername:String, aPassword:String ):void
		{
			var token:AsyncToken = service.getDatabases( aHost, aPort, aUsername, aPassword );
				token.addResponder( responder );
				token.host = aHost;
				token.port = aPort;
				token.username = aUsername;
				token.password = aPassword;
		}
		
		public function getTables( aHost:String, aPort:String, aUsername:String, aPassword:String, aDatabase:String ):void
		{
			var token:AsyncToken = service.getTables( aHost, aPort, aUsername, aPassword, aDatabase );
				token.addResponder( responder );
				token.host = aHost;
				token.port = aPort;
				token.username = aUsername;
				token.password = aPassword;
				token.database = aDatabase;
		}
		
		public function executeQuery( aHost:String, aPort:String, aUsername:String, aPassword:String, aDatabase:String, aQuery:String ):void
		{
			var token:AsyncToken = service.executeQuery( aHost, aPort, aUsername, aPassword, aDatabase, aQuery );
				token.addResponder( responder );
				token.host = aHost;
				token.port = aPort;
				token.username = aUsername;
				token.password = aPassword;
				token.database = aDatabase;
				token.query = aQuery;
		}
		
		public function describeTable( aHost:String, aPort:String, aUsername:String, aPassword:String, aDatabase:String, aTable:String ):void
		{
			var token:AsyncToken = service.describeTable( aHost, aPort, aUsername, aPassword, aDatabase, aTable );
				token.addResponder( responder );
				token.host = aHost;
				token.port = aPort;
				token.username = aUsername;
				token.password = aPassword;
				token.database = aDatabase;
				token.table = aTable;
		}
		
		public function getServices():void
		{
			var token:AsyncToken = service.getServices();
				token.addResponder( responder );	
		}
		
		public function describeService( aService:Object ):void
		{
			var token:AsyncToken = service.describeService( aService );
				token.addResponder( responder );
				token.service = aService;
		}
		
		public function getTemplates():void
		{
			var token:AsyncToken = service.getTemplates();
				token.addResponder( responder );	
		}
	}
}
